<script setup lang="ts">
import { onMounted, onUnmounted, ref } from "vue";
import Lottie from "lottie-web";
import startAniData from "@/assets/json/start.json";
import { useRouter } from "vue-router";

const router = useRouter();
const imgRef = ref<HTMLDivElement>();
const startAnimation = () => {
  Lottie.loadAnimation({
    container: imgRef.value!,
    renderer: "svg",
    loop: true,
    autoplay: true,
    animationData: startAniData
  });
};

onMounted(() => {
  startAnimation();
});

onUnmounted(() => {
  Lottie.destroy();
});

const handleStart = () => {
  router.push({ name: "home" });
};

</script>

<template>
  <div class="start">
    <div ref="imgRef" class="img" />

    <footer>
      <p>聚沙成塔，集腋成裘</p>
      <button type="button" class="start-btn" @click="handleStart">开始记账</button>
    </footer>
  </div>
</template>

<style lang="scss" scoped>
.start {
  height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  background: linear-gradient(to top, rgba(251, 33, 117, 0.66) 0%, #EF5350 100%);

  .img {
    height: 44vh;
    object-fit: contain;
  }
}


footer {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  border-radius: 20px;
  border: solid rgba(255, 255, 255, 0.5) 2px;
  background: var(--color-gold-secondary);
  padding: 40px 20px 20px;
  box-shadow: 0 0 5px 5px rgba(0, 0, 0, 0.1);

  p {
    color: white;
    font-weight: bold;
    font-size: 24px;
  }

  .start-btn {
    color: #fff;
    width: 250px;
    height: 60px;
    font-size: 22px;
    border-radius: 30px;
    margin: 30px 0;
    padding: 10px 25px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: inset 2px 2px 2px 0 rgba(255, 255, 255, .5),
    7px 7px 20px 0 rgba(0, 0, 0, .1),
    4px 4px 5px 0 rgba(0, 0, 0, .1);
    outline: none;
    border: none;
    background: rgb(251, 33, 117);
    background: linear-gradient(to left, rgba(251, 33, 117, 1) 0%, #EF5350 100%);
    overflow: hidden;
    letter-spacing: 10px;
    user-select: none;

    &:hover {
      text-decoration: none;
      color: #fff;
    }

    &:active {
      box-shadow: 4px 4px 6px 0 rgba(255, 255, 255, .3),
      -4px -4px 6px 0 rgba(116, 125, 136, .2),
      inset -4px -4px 6px 0 rgba(255, 255, 255, .2),
      inset 4px 4px 6px 0 rgba(0, 0, 0, .2);
    }

  }

  .skip-btn {
    color: var(--color-black-secondary);
    outline: none;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 20px;
    letter-spacing: 6px;
  }
}
</style>
